package ru.ifmo.filemanager.filesystem;

import java.io.IOException;

import ru.ifmo.filemanager.filesystem.interfaces.Directory;
import ru.ifmo.filemanager.filesystem.interfaces.DirectoryListReceiver;

public class DirectoryListTask implements Runnable {

	protected final Directory self;
	protected final DirectoryListReceiver receiver;
	
	public DirectoryListTask(Directory self, DirectoryListReceiver receiver) {
		this.self = self;
		this.receiver = receiver;
	}

	public void run() {
		run(self, receiver);
	}
	
	public static void run(Directory self, DirectoryListReceiver receiver) {
		String result[];
		try {
			result = self.list();
		} catch (IOException error) {
			receiver.directoryListFailure(self, error);
			return;
		}
		receiver.directoryListSuccess(self, result);
	}
}